package controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import bean.Customer;
import bean.Fund;
import bean.LoggedUser;
import bean.Model;
import bean.UserType;
import businessBean.CustomerRequestCheck;
import dao.CustomerDAO;

/*
 * 
 * Created By Sahil Thakkar for Request Check  Usecase
 */

public class OpenRequestCheckAction extends Action {
	
	private CustomerDAO customerDAO;
	public OpenRequestCheckAction(Model model) {
		customerDAO = model.getCustomerDAO();
	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "openRequestCheck.do";
	}

	@Override
	public String perform(HttpServletRequest request) {
		// TODO Auto-generated method stub
		String fundStr = null;
		Fund fund = null;
		try {
			
			HttpSession session     = request.getSession(false);
			LoggedUser user = (LoggedUser) session.getAttribute("user");
			
			Customer c = customerDAO.getCustomerById(""+user.getId());
			CustomerRequestCheck c1 = new CustomerRequestCheck();
			c1.setFirstname(c.getFirstname());
			c1.setLastname(c.getLastname());
			c1.setCash(util.Util.showMoney(c.getCash()));
		    request.setAttribute("customer", c1);
		    
			return "openRequestCheck.jsp";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "error.jsp";
		}
	}

	 @Override
		public UserType getType() {
		 return UserType.Customer;
	 }
}